﻿using Arrays;

int[] numbers = new int[10] { 1, 222, 23, 43, 5, 64, 74, 38, 29, 10 };

// IndexOf()
int n = Array.IndexOf(numbers, 2);
Console.WriteLine(n);

// Binary Search
int binarySearch = Array.BinarySearch(numbers, 10);

// Clear elements of array
Array.Clear(numbers, 1, 4);

// Resize array to 20
Array.Resize(ref numbers, 20);

// Sort
Array.Sort(numbers);

// Reverse
Array.Reverse(numbers);

// Multi-Dim Arrays
int[,] a = new int[4, 3]
{
    { 10, 20, 30 },
    { 30, 40, 50 },
    { 11, 12, 23 },
    { 12, 333, 3333 }
};

for (int row = 0; row < 4; row++)
{
    for (int col = 0; col < 3; col++)
    {
        Console.Write(a[row, col]);
        Console.Write(" ");
    }

    Console.WriteLine(" ");
}

// Jagged Array
int[][] jaggedArray = new int[3][];
jaggedArray[0] = new int[3] { 1, 2, 3 };
jaggedArray[1] = new int[2] { 111, 112 };
jaggedArray[2] = new int[5] { 11, 21, 13, 344, 90 };

for (int i = 0; i < 3; i++)
{
    for (int j = 0; j < jaggedArray[0].Length; j++)
    {
        Console.Write(jaggedArray[i][j]);
        Console.Write(" ");
    }

    Console.WriteLine(" ");
}

// Array of objects
Employee emp1 = new Employee() { Id = 1, Name = "jack" };
Employee emp2 = new Employee() { Id = 2, Name = "Tom" };
Employee emp3 = new Employee() { Id = 3, Name = "Castle" };


// create array of objects
Employee[] employees = new Employee[] { emp1, emp2, emp3 };
foreach (Employee item in employees)
{
    Console.WriteLine(item.Id + " " + item.Name);
}

// Copy To and Clone
Employee[] newEmployee = new Employee[3];
employees.CopyTo(newEmployee, 0);
foreach (var item in newEmployee)
{
    if (item is not null)
    {
        Console.WriteLine(item.Id + "-" + item.Name);
    }    
    
}



Console.ReadKey();